package com.example.test.启动线程.买票;

public class ShopTicket {

    public static void main(String[] args) {

        class MyThread implements Runnable {

            int num = 10;

            @Override
            public void run() {
                while (num > 0) {
                    maipiao();
                }
            }

            private synchronized void maipiao() {
                if (num > 0) {
                    System.out.println("卖出第" + num + "票");
                    num--;
                }
            }
        }

        MyThread myThread = new MyThread();
        Thread thread1 = new Thread(myThread);
        Thread thread2 = new Thread(myThread);
        Thread thread3 = new Thread(myThread);

        thread1.start();
        thread2.start();
        thread3.start();

    }

}
